home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / games / packman / pacman2.s < prev    next >
Text File  |  1980-01-03  |  26KB  |  1,126 lines

  1.  
  2. ; part 3
  3.  
  4. ; 'pacman2.s' source , see accompaning text in the July 1994 issue
  5. ; of Amiga computing . Written by Mark Jackson using Devpac 3.02
  6.  
  7. ; this month I've added the background graphics , and (after hours of
  8. ; trying!) I finally got the movement routines to work the way I
  9. ; wanted them to . So now pacman moves in the paths , and for example
  10. ; when you're moving right along a path and press up , at then next
  11. ; opportunity pacman will go up a path! .
  12.  
  13.  
  14.  
  15.     section    pacman,code_c        ; put in CHIP memory
  16. ;    opt    c-,o+            ; not case-sensitive
  17.                     ; optimisation on
  18.  
  19.  
  20.     move.l    4.w,a6            ; execbase
  21.     jsr    forbid(a6)        ; turn off multitasking!
  22.  
  23.     lea    $dff000,a5        ; a5 always points to
  24.                     ; register's base address
  25.  
  26.     lea    gfx_lib,a1        ; name of library to open
  27.     moveq    #0,d0            ; version number unimportant
  28.     move.l    4.w,a6            ; execbase
  29.     jsr    openlib(a6)        ; open graphics-library
  30.     move.l    d0,gfx_base        ; save base address
  31.  
  32.  
  33.     move.l    #screen,d0        ; address of first bitplane
  34.     move.w    d0,pl1l            ; set pointer low word
  35.     swap    d0
  36.     move.w    d0,pl1h            ; and high word
  37.  
  38.     move.l    #screen+40*256,d0
  39.     move.w    d0,pl2l
  40.     swap    d0
  41.     move.w    d0,pl2h
  42.  
  43.     move.l    #screen+40*256*2,d0
  44.     move.w    d0,pl3l
  45.     swap    d0
  46.     move.w    d0,pl3h
  47.  
  48.  
  49.     move.l    #sprite1,d0        ; address of sprite
  50.     move.w    d0,sp0l            ; set pointer low word
  51.     swap    d0
  52.     move.w    d0,sp0h            ; and high word
  53.  
  54.     move.l    #sprite2,d0
  55.     move.w    d0,sp1l
  56.     swap    d0
  57.     move.w    d0,sp1h
  58.  
  59.  
  60.     move.l    gfx_base,a6        ; graphics-library base address
  61.     move.w    #$80,dmacon(a5)        ; turn copper dma off
  62.     move.l    $32(a6),old_copper    ; save address of old copper-list
  63.     move.l    #new_copper,$32(a6)    ; insert our new copper-list
  64.     move.w    #$8080,dmacon(a5)    ; and turn copper dma back on!
  65.  
  66.  
  67. start_game:                ; reset all variables ->
  68.     move.w    #151,x            ; pacman x-coordinate
  69.     move.w    #156,y            ; pacman y-coordinate
  70.     move.w    #1,dir            ; pacman direction
  71.     move.w    #1,dir2            ; set other to same (see later)
  72.     move.w    #0,score        ; player's score
  73.     move.w    #5,lives        ; player's number of lives
  74.  
  75.     bsr    draw_lives        ; draw the number of lives
  76.     bsr    print_score
  77.     bsr    draw_pacman        ; put pacman on screen
  78.  
  79.     bsr    ready            ; print 'are you ready?' and wait
  80.  
  81. main_loop:
  82.     move.b    vhposr(a5),d0        ; get scanline
  83.     cmp.b    #$ff,d0            ; reached line $ff?
  84.     bne.s    main_loop        ; not yet
  85.  
  86.  
  87.     bsr    read_joystick        ; read joystick and adjust coords
  88.     bsr    draw_pacman        ; put sprite in correct position
  89.     bsr    animate_pacman        ; animate sprite
  90.  
  91.     bsr    print_score
  92.     bsr    draw_lives        ; draw number of lives on screen
  93.  
  94.  
  95.     move.b    $bfec01,d0        ; read keyboard (raw keycode)
  96.     eor.b    #$ff,d0            ; decode byte
  97.     ror.b    #1,d0
  98.  
  99.     cmp.b    #$45,d0            ; escape key pressed?
  100.     beq.s    quit_game        ; if so then quit game!
  101.  
  102.     cmp.b    #$10,d0            ; 'q' key pressed?
  103.     beq.s    start_game        ; if so then restart game
  104.  
  105.     cmp.b    #$19,d0            ; 'p' key pressed?
  106.     bne.s    no_pause        ; no - carry on
  107.     bsr    pause_game        ; else pause game
  108. no_pause:
  109.  
  110.     tst.w    lives            ; have player's lives reached zero?
  111.     bne.s    main_loop        ; nope - do loop again!
  112.  
  113.     bsr    game_over        ; else print 'game over' , etc.
  114.     bra    start_game        ; and start again
  115.  
  116.  
  117. quit_game:
  118.     move.l    gfx_base,a6        ; graphics-library base address
  119.     move.w    #$80,dmacon(a5)        ; copper dma off
  120.     move.l    old_copper,$32(a6)    ; restore system copper-list
  121.     move.w    #$8080,dmacon(a5)    ; copper dma on
  122.  
  123.     move.l    gfx_base,a1        ; graphics-library base address
  124.     move.l    4.w,a6            ; execbase
  125.     jsr    closelib(a6)        ; close library
  126. error:
  127.     move.l    4.w,a6            ; execbase
  128.     jsr    permit(a6)        ; multitasking on
  129.  
  130.     moveq    #0,d0            ; no errors , please!
  131.     rts                ; and return to CLI
  132.  
  133.  
  134. old_copper:                ; space to store address of
  135.     dc.l    0            ; system copper-list
  136.  
  137. new_copper:                ; our new copper-list
  138.     dc.w    bplcon0,$3200        ; 5 bitplane (32 colour) screen
  139.     dc.w    bplcon1,0        ; hardware-scroll value
  140.     dc.w    bplcon2,$20        ; video priority
  141.     dc.w    bpl1mod,0        ; bitplane modulo (odd bitplanes)
  142.     dc.w    bpl2mod,0        ; bitplane modulo (even bitplanes)
  143.     dc.w    ddfstrt,$38        ; left edge of screen
  144.     dc.w    ddfstop,$d0        ; right edge of screen
  145.     dc.w    diwstrt,$2c81        ; top left corner of screen
  146.     dc.w    diwstop,$2cc1        ; bottom right corner of screen
  147.  
  148.  
  149.     dc.w    bpl1pth                ; bitplane pointers
  150. pl1h:    dc.w    0,bpl1ptl
  151. pl1l:    dc.w    0,bpl2pth
  152. pl2h:    dc.w    0,bpl2ptl
  153. pl2l:    dc.w    0,bpl3pth
  154. pl3h:    dc.w    0,bpl3ptl
  155. pl3l:    dc.w    0
  156.  
  157.     dc.w    spr0pth                ; sprite pointers
  158. sp0h:    dc.w    0,spr0ptl
  159. sp0l:    dc.w    0,spr1pth
  160. sp1h:    dc.w    0,spr1ptl
  161. sp1l:    dc.w    0,spr2pth
  162. sp2h:    dc.w    0,spr2ptl
  163. sp2l:    dc.w    0,spr3pth
  164. sp3h:    dc.w    0,spr3ptl
  165. sp3l:    dc.w    0,spr4pth
  166. sp4h:    dc.w    0,spr4ptl
  167. sp4l:    dc.w    0,spr5pth
  168. sp5h:    dc.w    0,spr5ptl
  169. sp5l:    dc.w    0,spr6pth
  170. sp6h:    dc.w    0,spr6ptl
  171. sp6l:    dc.w    0,spr7pth
  172. sp7h:    dc.w    0,spr7ptl
  173. sp7l:    dc.w    0
  174.  
  175.  
  176.     dc.w    colour0,$000            ; colours at top of screen
  177.     dc.w    colour1,$fff
  178.     dc.w    colour2,$ff0
  179.     dc.w    colour3,$660
  180.  
  181.     dc.w    $3801,$ff00,colour0,$fff    ; draw a little copper bar
  182.     dc.w    $3901,$ff00,colour0,$666
  183.     dc.w    $3a01,$ff00,colour0,$000
  184.  
  185.     dc.w    colour1,$000            ; main screen's colours
  186.     dc.w    colour2,$fff
  187.     dc.w    colour3,$f00
  188.     dc.w    colour4,$332
  189.     dc.w    colour5,$fff
  190.     dc.w    colour6,$fff
  191.     dc.w    colour7,$fff
  192.  
  193.     dc.w    colour18,$04e            ; pacman's colours
  194.     dc.w    colour19,$ff4
  195.     dc.w    colour20,$ff0
  196.     dc.w    colour21,$ee0
  197.     dc.w    colour22,$dd0
  198.     dc.w    colour23,$cc0
  199.     dc.w    colour24,$bb0
  200.     dc.w    colour25,$aa0
  201.     dc.w    colour26,$05f
  202.     dc.w    colour27,$03d
  203.     dc.w    colour28,$02c
  204.     dc.w    colour29,$eee
  205.     dc.w    colour30,$ddd
  206.     dc.w    colour31,$ccc
  207.  
  208.     dc.w    $ffff,$fffe            ; end of copper-list
  209.     dc.w    $ffff,$fffe            ; (should be done twice!)
  210.  
  211.  
  212.  
  213. ************  read joystick  ************
  214.  
  215.  
  216. read_joystick:
  217.     move.w    $c(a5),d0            ; read joy0dat
  218.  
  219.     btst    #9,d0
  220.     beq.s    l
  221.     move.w    #0,dir2                ; set direction
  222. l:
  223.     btst    #1,d0
  224.     beq.s    r
  225.     move.w    #1,dir2                ; set direction
  226. r:
  227.     move.w    d0,d1                ; make copy of joy0dat
  228.     and.w    #$3,d1                ; and out unwanted bits
  229.     cmp.w    #$2,d1
  230.     beq.s    down
  231.     cmp.w    #$1,d1
  232.     bne.s    d
  233. down:
  234.     move.w    #2,dir2                ; set direction
  235. d:
  236.     and.w    #$300,d0
  237.     cmp.w    #$200,d0
  238.     beq.s    up
  239.     cmp.w    #$100,d0
  240.     bne.s    u
  241. up:
  242.     move.w    #3,dir2                ; set direction
  243. u:
  244.     rts
  245.  
  246.  
  247.  
  248. ************  draw pacman  ************
  249.  
  250.  
  251. draw_pacman:
  252.     move.w    dir2,d2                ; direction pac wants to go
  253.     bsr    test_dir            ; test if it's possible
  254.     tst.b    d4                ; test flag
  255.     bne.s    dir2_blocked            ; it's not possible!
  256.     move.w    dir2,dir            ; if it is then set real dir
  257.     bra.s    draw_pacman2            ; and draw pacman
  258.  
  259. dir2_blocked:
  260.     move.w    dir,d2                ; pac's direction
  261.     bsr    test_dir            ; test if path is blocked
  262.     tst.b    d4                ; test flag
  263.     beq.s    draw_pacman2            ; if zero then ok to draw
  264.     rts                    ; else if set then skip
  265.  
  266.  
  267. draw_pacman2:
  268.     move.w    dir,d0                ; get direction (0-3)
  269.     lea    dir_tab,a0            ; and direction table
  270.     lsl    #2,d0                ; times 4
  271.     lea    (a0,d0),a0            ; get start word
  272.     move.w    (a0)+,dx            ; set x speed
  273.     move.w    (a0),dy                ; and y speed
  274.  
  275.     move.w    dx,d0                ; get x-speed
  276.     move.w    dy,d1                ; and y-speed
  277.     add.w    d0,x                ; add x-speed to x-coordinate
  278.     add.w    d1,y                ; add y-speed to y-coordinate
  279.  
  280.     move.l    #0,sprite1            ; clear control words
  281.     move.l    #0,sprite2            ; and on second sprite
  282.  
  283.     move.w    x,d0                ; our x-coordinate (word)
  284.     move.w    y,d1                ; and y-coordinate (word)
  285.  
  286.     add.w    #$80,d0                ; $80 = left edge of screen
  287.     add.w    #$2c,d1                ; $2c = top edge of screen
  288.  
  289.     move.w    d1,d2                ; don't touch original value
  290.     move.b    d2,sprite1            ; set y low 8 bits
  291.     add.w    #$10,d2                ; add height of sprite
  292.     move.b    d2,sprite1+$2            ; set 'last line' low 8 bits
  293.  
  294.     move.w    d0,d2                ; work on copy of x-coord
  295.     lsr    #1,d2                ; shift right 1 bit
  296.     move.b    d2,sprite1+$1            ; set x high 8 bits
  297.  
  298.     move.w    d1,d2                ; copy y-coord to 'd2'
  299.     and.w    #$100,d2            ; and out unwanted bits
  300.     lsr    #6,d2                ; shift right by 6 bits
  301.     or.b    d2,sprite1+$3            ; set y high bit
  302.  
  303.     add.w    #$10,d1                ; add height of sprite
  304.     and.w    #$100,d1            ; and out unwanted bits
  305.     lsr    #7,d1                ; shift right by 7 bits
  306.     or.b    d1,sprite1+$3            ; set 'last line' high bit
  307.  
  308.     and.b    #$1,d0                ; and out unwanted bits
  309.     or.b    d0,sprite1+$3            ; set x low bit
  310.  
  311.     move.l    sprite1,sprite2            ; copy control words over
  312.     or.b    #$80,sprite2+$3            ; and set 'attach' bit
  313.     rts
  314.  
  315.  
  316.  
  317. ************  test direction  ************
  318.  
  319.  
  320. test_dir:
  321.     lea    screen,a0            ; start of screen
  322.     move.w    x,d0                ; pacman's x-coordinate
  323.     move.w    y,d1                ; pacman's y-coordinate
  324.     move.w    #0,d4                ; collision flag
  325.  
  326. test_left:
  327.     tst.w    d2                ; is 'dir' zero?
  328.     bne    test_right            ; no - not going left
  329.  
  330.     subq.w    #1,d0                ; test pixels to pac's left
  331.     mulu    #40,d1                ; y * 40 bytes per line
  332.     lea    (a0,d1),a0            ; start line
  333.     move.w    d0,d1                ; make copy of x-coord
  334.     lsr    #3,d0                ; divided by 8 = no. bytes
  335.     lea    (a0,d0),a0            ; point to start byte
  336.     lsl    #3,d0                ; times 8 again
  337.     sub.w    d0,d1                ; get number of pixel
  338.     move.w    #7,d0                ; take this from 7
  339.     sub.w    d1,d0                ; gives us bit number!
  340.  
  341.     btst    d0,(a0)                ; test that bit
  342.     bne.s    path_in_way_l            ; if set then path in way
  343.     btst    d0,40(a0)            ; do this for all 16 lines
  344.     bne.s    path_in_way_l
  345.     btst    d0,40*2(a0)
  346.     bne.s    path_in_way_l
  347.     btst    d0,40*3(a0)
  348.     bne.s    path_in_way_l
  349.     btst    d0,40*4(a0)
  350.     bne.s    path_in_way_l
  351.     btst    d0,40*5(a0)
  352.     bne.s    path_in_way_l
  353.     btst    d0,40*6(a0)
  354.     bne.s    path_in_way_l
  355.     btst    d0,40*7(a0)
  356.     bne.s    path_in_way_l
  357.     btst    d0,40*8(a0)
  358.     bne.s    path_in_way_l
  359.     btst    d0,40*9(a0)
  360.     bne.s    path_in_way_l
  361.     btst    d0,40*10(a0)
  362.     bne.s    path_in_way_l
  363.     btst    d0,40*11(a0)
  364.     bne.s    path_in_way_l
  365.     btst    d0,40*12(a0)
  366.     bne.s    path_in_way_l
  367.     btst    d0,40*13(a0)
  368.     bne.s    path_in_way_l
  369.     btst    d0,40*14(a0)
  370.     bne.s    path_in_way_l
  371.     btst    d0,40*15(a0)
  372.     bne.s    path_in_way_l
  373.     rts                    ; all clear!
  374. path_in_way_l:
  375.     move.b    #1,d4                ; set collision flag
  376.     rts                    ; and return
  377.  
  378. test_right:
  379.     cmp.w    #1,d2                ; do same for right
  380.     bne    test_down
  381.  
  382.     add.w    #16,d0
  383.     mulu    #40,d1
  384.     lea    (a0,d1),a0
  385.     move.w    d0,d1
  386.     lsr    #3,d0
  387.     lea    (a0,d0),a0
  388.     lsl    #3,d0
  389.     sub.w    d0,d1
  390.     move.w    #7,d0
  391.     sub.w    d1,d0
  392.  
  393.     btst    d0,(a0)
  394.     bne.s    path_in_way_r
  395.     btst    d0,40(a0)
  396.     bne.s    path_in_way_r
  397.     btst    d0,40*2(a0)
  398.     bne.s    path_in_way_r
  399.     btst    d0,40*3(a0)
  400.     bne.s    path_in_way_r
  401.     btst    d0,40*4(a0)
  402.     bne.s    path_in_way_r
  403.     btst    d0,40*5(a0)
  404.     bne.s    path_in_way_r
  405.     btst    d0,40*6(a0)
  406.     bne.s    path_in_way_r
  407.     btst    d0,40*7(a0)
  408.     bne.s    path_in_way_r
  409.     btst    d0,40*8(a0)
  410.     bne.s    path_in_way_r
  411.     btst    d0,40*9(a0)
  412.     bne.s    path_in_way_r
  413.     btst    d0,40*10(a0)
  414.     bne.s    path_in_way_r
  415.     btst    d0,40*11(a0)
  416.     bne.s    path_in_way_r
  417.     btst    d0,40*12(a0)
  418.     bne.s    path_in_way_r
  419.     btst    d0,40*13(a0)
  420.     bne.s    path_in_way_r
  421.     btst    d0,40*14(a0)
  422.     bne.s    path_in_way_r
  423.     btst    d0,40*15(a0)
  424.     bne.s    path_in_way_r
  425.     rts
  426. path_in_way_r:
  427.     move.b    #1,d4
  428.     rts
  429.  
  430. test_down:
  431.     cmp.w    #2,d2
  432.     bne.s    test_up
  433.  
  434.     add.w    #16,d1
  435.     mulu    #40,d1
  436.     lea    (a0,d1),a0
  437.     move.w    d0,d1
  438.     lsr    #3,d0
  439.     lea    (a0,d0),a0
  440.     lsl    #3,d0
  441.     sub.w    d0,d1
  442.     move.w    #7,d0
  443.     sub.w    d1,d0
  444.  
  445.     move.w    #16-1,d3            ; test 16 pixels below...
  446. t_down_loop:
  447.     btst    d0,(a0)                ; test bit
  448.     bne.s    path_in_way_d            ; if set then that's it!
  449.     tst.w    d0                ; is bit no. zero?
  450.     beq.s    overflow_d            ; yes - need next byte
  451.     subq.w    #1,d0                ; else next bit in byte
  452.     dbra    d3,t_down_loop            ; and loop back
  453.     rts
  454. overflow_d:
  455.     move.w    #7,d0                ; start bit = 7
  456.     lea    1(a0),a0            ; point to next byte
  457.     dbra    d3,t_down_loop            ; and loop back
  458.     rts
  459.  
  460. path_in_way_d:
  461.     move.b    #1,d4
  462.     rts
  463.  
  464. test_up:
  465.     subq.w    #1,d1                ; do same for up direction
  466.     mulu    #40,d1
  467.     lea    (a0,d1),a0
  468.     move.w    d0,d1
  469.     lsr    #3,d0
  470.     lea    (a0,d0),a0
  471.     lsl    #3,d0
  472.     sub.w    d0,d1
  473.     move.w    #7,d0
  474.     sub.w    d1,d0
  475.  
  476.     move.w    #16-1,d3
  477. t_up_loop:
  478.     btst    d0,(a0)
  479.     bne.s    path_in_way_u
  480.     tst.w    d0
  481.     beq.s    overflow_u
  482.     subq.w    #1,d0
  483.     dbra    d3,t_up_loop
  484.     rts
  485. overflow_u:
  486.     move.w    #7,d0
  487.     lea    1(a0),a0
  488.     dbra    d3,t_up_loop
  489.     rts
  490.  
  491. path_in_way_u:
  492.     move.b    #1,d4
  493.     rts
  494.  
  495.  
  496.  
  497. ************  animate pacman  ************
  498.  
  499.  
  500. animate_pacman:
  501.     lea    pacman_gfx,a0            ; start of pacman graphics
  502.     lea    sprite1+$4,a1            ; the gfx part of sprite1
  503.     lea    sprite2+$4,a2            ; the gfx part of sprite2
  504.  
  505.     move.w    dir,d0                ; direction of pacman (0-3)
  506.  
  507.  
  508.     mulu    #16*4*2*10,d0            ; times length of gfx blocks
  509.     lea    (a0,d0),a0            ; start of gfx data
  510.  
  511.     addq.w    #1,pacman_anim            ; pacman animation number
  512.     cmp.w    #10,pacman_anim            ; have we reached end?
  513.     bne.s    pacman_anim_ok            ; nope - we're ok!
  514.     move.w    #0,pacman_anim            ; else reset anim number
  515. pacman_anim_ok:
  516.     move.w    pacman_anim,d0            ; get animation number
  517.     mulu    #16*4*2,d0            ; times length of gfx block
  518.     lea    (a0,d0),a0            ; this is the one!!!
  519.  
  520.     move.w    #16-1,d0            ; pacman = 16 lines high
  521. pac_loop1:
  522.     move.l    (a0)+,(a1)+            ; move in longword
  523.     dbra    d0,pac_loop1            ; Decrement and BRAnch
  524.  
  525.     move.w    #16-1,d0            ; pacman = 16 lines high
  526. pac_loop2:
  527.     move.l    (a0)+,(a2)+            ; move in longword
  528.     dbra    d0,pac_loop2            ; Decrement and BRAnch
  529.     rts
  530.  
  531.  
  532.  
  533. ************  draw lives  ************
  534.  
  535.  
  536. draw_lives:
  537.     lea    screen,a1            ; where to draw lives
  538.     move.w    lives,d0            ; number of lives
  539.     subq.w    #1,d0                ; take one , for dbra
  540. lives_loop:
  541.     move.b    #$44,(a1)            ; draw little pacman!
  542.     move.b    #$80,40(a1)            ; first bitplane
  543.     move.b    #$00,40*2(a1)
  544.     move.b    #$00,40*3(a1)
  545.     move.b    #$00,40*4(a1)
  546.     move.b    #$80,40*5(a1)
  547.     move.b    #$44,40*6(a1)
  548.  
  549.     move.b    #$7c,40*256(a1)            ; and second bitplane
  550.     move.b    #$ec,40*256+40(a1)        ; (to give 4 colours)
  551.     move.b    #$f8,40*256+40*2(a1)
  552.     move.b    #$f0,40*256+40*3(a1)
  553.     move.b    #$f8,40*256+40*4(a1)
  554.     move.b    #$fc,40*256+40*5(a1)
  555.     move.b    #$7c,40*256+40*6(a1)
  556.  
  557.     lea    1(a1),a1            ; next byte on screen
  558.     dbra    d0,lives_loop            ; and repeat...
  559.  
  560.     move.b    #0,d0                ; put a zero in D0
  561.     move.b    d0,(a1)                ; and copy to screen
  562.     move.b    d0,40(a1)            ; this is quicker than
  563.     move.b    d0,40*2(a1)            ; 'move.b #0,(a1)' , etc.
  564.     move.b    d0,40*3(a1)
  565.     move.b    d0,40*4(a1)
  566.     move.b    d0,40*5(a1)
  567.     move.b    d0,40*6(a1)
  568.     move.b    d0,40*7(a1)
  569.  
  570.     move.b    d0,40*256(a1)            ; clear second bitplane too
  571.     move.b    d0,40*256+40(a1)
  572.     move.b    d0,40*256+40*2(a1)
  573.     move.b    d0,40*256+40*3(a1)
  574.     move.b    d0,40*256+40*4(a1)
  575.     move.b    d0,40*256+40*5(a1)
  576.     move.b    d0,40*256+40*6(a1)
  577.     move.b    d0,40*256+40*7(a1)
  578.     rts
  579.  
  580.  
  581.  
  582. ************  print score  ************
  583.  
  584.  
  585. print_score:
  586.     move.w    score,d2            ; get score (stored in word)
  587.  
  588. digit4:
  589.     lea    numbers,a0            ; start of numbers gfx data
  590.     cmp.w    #1000,d2            ; compare 1000 to score
  591.     bge.s    do_1000                ; score = 1000 or above
  592.     lea    screen+18,a6            ; else print '0'
  593.     bsr    print                ; print it
  594.     bra.s    digit3                ; and go onto next digit
  595. do_1000:
  596.     divu.w    #1000,d2            ; divide score by 1000
  597.     move.w    d2,d3                ; save value
  598.     clr    d2                ; clear
  599.     swap    d2                ; swap words
  600.     lea    (a0,d3),a0            ; get number
  601.     lea    screen+18,a6            ; where to print
  602.     bsr.s    print                ; and print it
  603.  
  604. digit3:
  605.     lea    numbers,a0
  606.     cmp.w    #100,d2
  607.     bge.s    do_100
  608.     lea    screen+19,a6
  609.     bsr.s    print
  610.     bra.s    digit2
  611. do_100:
  612.     divu.w    #100,d2
  613.     move.w    d2,d3
  614.     clr    d2
  615.     swap    d2
  616.     lea    (a0,d3),a0
  617.     lea    screen+19,a6
  618.     bsr.s    print
  619.  
  620. digit2:
  621.     lea    numbers,a0
  622.     cmp.w    #10,d2
  623.     bge.s    do_10
  624.     lea    screen+20,a6
  625.     bsr.s    print
  626.     bra.s    digit1
  627. do_10:
  628.     divu.w    #10,d2
  629.     move.w    d2,d3
  630.     clr    d2
  631.     swap    d2
  632.     lea    (a0,d3),a0
  633.     lea    screen+20,a6
  634.     bsr.s    print
  635.  
  636. digit1:
  637.     lea    numbers,a0
  638.     cmp.w    #1,d2
  639.     bge.s    do_1
  640.     lea    screen+21,a6
  641.     bsr.s    print
  642.     bra.s    numbers_done
  643. do_1:
  644.     lea    (a0,d2),a0
  645.     lea    screen+21,a6
  646.     bsr.s    print
  647. numbers_done:
  648.     rts
  649.  
  650.  
  651. print:
  652.     move.b    (a0),(a6)
  653.     move.b    10(a0),40(a6)
  654.     move.b    10*2(a0),40*2(a6)
  655.     move.b    10*3(a0),40*3(a6)
  656.     move.b    10*4(a0),40*4(a6)
  657.     move.b    10*5(a0),40*5(a6)
  658.     move.b    10*6(a0),40*6(a6)
  659.     move.b    10*7(a0),40*7(a6)
  660.     rts
  661.  
  662.  
  663.  
  664. ************  are you ready?  ************
  665.  
  666.  
  667. ready:
  668.     lea    screen+(40*110)+12,a0
  669.     lea    gfx_buffer,a1
  670.  
  671.     bsr    blitter_wait            ; wait for blitter
  672.  
  673.     move.l    a0,$50(a5)            ; A channel = source
  674.     move.l    a1,$54(a5)            ; D channel = destination
  675.     move.w    #24,$64(a5)            ; A channel modulo
  676.     move.w    #0,$66(a5)            ; D channel modulo
  677.     move.w    #$09f0,$40(a5)            ; function = straight copy
  678.     move.w    #0,$42(a5)            ; second control word
  679.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  680.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  681.  
  682.     lea    40*256(a0),a0            ; next bitplane on screen
  683.     lea    16*26(a1),a1            ; next bitplane in buffer
  684.  
  685.     bsr    blitter_wait            ; wait for blitter
  686.  
  687.     move.l    a0,$50(a5)            ; A channel = source
  688.     move.l    a1,$54(a5)            ; D channel = destination
  689.     move.w    #24,$64(a5)            ; A channel modulo
  690.     move.w    #0,$66(a5)            ; D channel modulo
  691.     move.w    #$09f0,$40(a5)            ; function = straight copy
  692.     move.w    #0,$42(a5)            ; second control word
  693.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  694.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  695.  
  696.  
  697.     lea    ready_gfx,a0
  698.     lea    screen+(40*110)+12,a1
  699.  
  700.     bsr    blitter_wait            ; wait for blitter
  701.  
  702.     move.l    a0,$50(a5)            ; A channel = source
  703.     move.l    a1,$54(a5)            ; D channel = destination
  704.     move.w    #0,$64(a5)            ; A channel modulo
  705.     move.w    #24,$66(a5)            ; D channel modulo
  706.     move.w    #$09f0,$40(a5)            ; function = straight copy
  707.     move.w    #0,$42(a5)            ; second control word
  708.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  709.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  710.  
  711.     lea    40*256(a1),a1            ; draw on next bitplane too!
  712.  
  713.     bsr    blitter_wait            ; wait for blitter
  714.  
  715.     move.l    a0,$50(a5)            ; A channel = source
  716.     move.l    a1,$54(a5)            ; D channel = destination
  717.     move.w    #0,$64(a5)            ; A channel modulo
  718.     move.w    #24,$66(a5)            ; D channel modulo
  719.     move.w    #$09f0,$40(a5)            ; function = straight copy
  720.     move.w    #0,$42(a5)            ; second control word
  721.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  722.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  723.  
  724.  
  725. ready_wait:
  726.     move.b    vhposr(a5),d0            ; get scanline
  727.     cmp.b    #$ff,d0                ; reached line $ff?
  728.     bne.s    ready_wait            ; not yet
  729.  
  730.     bsr    animate_pacman            ; animate pacman sprite
  731.  
  732.     move.b    $bfe001,d0            ; read hardware register
  733.     btst    #7,d0                ; fire-button = bit 7
  734.     bne.s    ready_wait            ; not pressed - wait again!
  735.  
  736.     lea    gfx_buffer,a0
  737.     lea    screen+(40*110)+12,a1
  738.  
  739.     bsr    blitter_wait            ; wait for blitter
  740.  
  741.     move.l    a0,$50(a5)            ; A channel = source
  742.     move.l    a1,$54(a5)            ; D channel = destination
  743.     move.w    #0,$64(a5)            ; A channel modulo
  744.     move.w    #24,$66(a5)            ; D channel modulo
  745.     move.w    #$09f0,$40(a5)            ; function = straight copy
  746.     move.w    #0,$42(a5)            ; second control word
  747.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  748.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  749.  
  750.     lea    16*26(a0),a0
  751.     lea    40*256(a1),a1
  752.  
  753.     bsr    blitter_wait            ; wait for blitter
  754.  
  755.     move.l    a0,$50(a5)            ; A channel = source
  756.     move.l    a1,$54(a5)            ; D channel = destination
  757.     move.w    #0,$64(a5)            ; A channel modulo
  758.     move.w    #24,$66(a5)            ; D channel modulo
  759.     move.w    #$09f0,$40(a5)            ; function = straight copy
  760.     move.w    #0,$42(a5)            ; second control word
  761.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  762.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  763.     rts
  764.  
  765.  
  766.  
  767. ************  pause game  ************
  768.  
  769.  
  770. pause_game:
  771.     lea    screen+(40*110)+12,a0
  772.     lea    gfx_buffer,a1
  773.  
  774.     bsr    blitter_wait            ; wait for blitter
  775.  
  776.     move.l    a0,$50(a5)            ; A channel = source
  777.     move.l    a1,$54(a5)            ; D channel = destination
  778.     move.w    #24,$64(a5)            ; A channel modulo
  779.     move.w    #0,$66(a5)            ; D channel modulo
  780.     move.w    #$09f0,$40(a5)            ; function = straight copy
  781.     move.w    #0,$42(a5)            ; second control word
  782.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  783.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  784.  
  785.     lea    40*256(a0),a0
  786.     lea    16*26(a1),a1
  787.  
  788.     bsr    blitter_wait            ; wait for blitter
  789.  
  790.     move.l    a0,$50(a5)            ; A channel = source
  791.     move.l    a1,$54(a5)            ; D channel = destination
  792.     move.w    #24,$64(a5)            ; A channel modulo
  793.     move.w    #0,$66(a5)            ; D channel modulo
  794.     move.w    #$09f0,$40(a5)            ; function = straight copy
  795.     move.w    #0,$42(a5)            ; second control word
  796.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  797.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  798.  
  799.  
  800.     lea    pause_gfx,a0
  801.     lea    screen+(40*110)+12,a1
  802.  
  803.     bsr    blitter_wait            ; wait for blitter
  804.  
  805.     move.l    a0,$50(a5)            ; A channel = source
  806.     move.l    a1,$54(a5)            ; D channel = destination
  807.     move.w    #0,$64(a5)            ; A channel modulo
  808.     move.w    #24,$66(a5)            ; D channel modulo
  809.     move.w    #$09f0,$40(a5)            ; function = straight copy
  810.     move.w    #0,$42(a5)            ; second control word
  811.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  812.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  813.  
  814.     lea    40*256(a1),a1
  815.  
  816.     bsr    blitter_wait            ; wait for blitter
  817.  
  818.     move.l    a0,$50(a5)            ; A channel = source
  819.     move.l    a1,$54(a5)            ; D channel = destination
  820.     move.w    #0,$64(a5)            ; A channel modulo
  821.     move.w    #24,$66(a5)            ; D channel modulo
  822.     move.w    #$09f0,$40(a5)            ; function = straight copy
  823.     move.w    #0,$42(a5)            ; second control word
  824.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  825.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  826.  
  827.  
  828. ps_wait:
  829.     move.b    $bfec01,d0            ; read keyboard
  830.     eor.b    #$ff,d0
  831.     ror.b    #1,d0
  832.  
  833.     cmp.b    #$19,d0                ; is 'p' still pressed?
  834.     beq.s    ps_wait                ; wait till it's released
  835.  
  836. ps_wait2:
  837.     move.b    $bfec01,d0
  838.     eor.b    #$ff,d0
  839.     ror.b    #1,d0
  840.  
  841.     cmp.b    #$19,d0                ; is 'p' pressed?
  842.     bne.s    ps_wait2            ; wait till it is again
  843.  
  844. ps_wait3:
  845.     move.b    $bfec01,d0
  846.     eor.b    #$ff,d0
  847.     ror.b    #1,d0
  848.  
  849.     cmp.b    #$19,d0                ; is 'p' still pressed?
  850.     beq.s    ps_wait3            ; wait till it's not!!!
  851.  
  852.  
  853.     lea    gfx_buffer,a0
  854.     lea    screen+(40*110)+12,a1
  855.  
  856.     bsr    blitter_wait            ; wait for blitter
  857.  
  858.     move.l    a0,$50(a5)            ; A channel = source
  859.     move.l    a1,$54(a5)            ; D channel = destination
  860.     move.w    #0,$64(a5)            ; A channel modulo
  861.     move.w    #24,$66(a5)            ; D channel modulo
  862.     move.w    #$09f0,$40(a5)            ; function = straight copy
  863.     move.w    #0,$42(a5)            ; second control word
  864.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  865.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  866.  
  867.     lea    16*26(a0),a0
  868.     lea    40*256(a1),a1
  869.  
  870.     bsr    blitter_wait            ; wait for blitter
  871.  
  872.     move.l    a0,$50(a5)            ; A channel = source
  873.     move.l    a1,$54(a5)            ; D channel = destination
  874.     move.w    #0,$64(a5)            ; A channel modulo
  875.     move.w    #24,$66(a5)            ; D channel modulo
  876.     move.w    #$09f0,$40(a5)            ; function = straight copy
  877.     move.w    #0,$42(a5)            ; second control word
  878.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  879.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  880.     rts
  881.  
  882.  
  883.  
  884. ************  game over  ************
  885.  
  886.  
  887. game_over:
  888.     lea    screen+(40*110)+12,a0
  889.     lea    gfx_buffer,a1
  890.  
  891.     bsr    blitter_wait            ; wait for blitter
  892.  
  893.     move.l    a0,$50(a5)            ; A channel = source
  894.     move.l    a1,$54(a5)            ; D channel = destination
  895.     move.w    #24,$64(a5)            ; A channel modulo
  896.     move.w    #0,$66(a5)            ; D channel modulo
  897.     move.w    #$09f0,$40(a5)            ; function = straight copy
  898.     move.w    #0,$42(a5)            ; second control word
  899.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  900.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  901.  
  902.     lea    40*256(a0),a0
  903.     lea    16*26(a1),a1
  904.  
  905.     bsr    blitter_wait            ; wait for blitter
  906.  
  907.     move.l    a0,$50(a5)            ; A channel = source
  908.     move.l    a1,$54(a5)            ; D channel = destination
  909.     move.w    #24,$64(a5)            ; A channel modulo
  910.     move.w    #0,$66(a5)            ; D channel modulo
  911.     move.w    #$09f0,$40(a5)            ; function = straight copy
  912.     move.w    #0,$42(a5)            ; second control word
  913.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  914.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  915.  
  916.  
  917.     lea    game_over_gfx,a0
  918.     lea    screen+(40*110)+12,a1
  919.  
  920.     bsr    blitter_wait            ; wait for blitter
  921.  
  922.     move.l    a0,$50(a5)            ; A channel = source
  923.     move.l    a1,$54(a5)            ; D channel = destination
  924.     move.w    #0,$64(a5)            ; A channel modulo
  925.     move.w    #24,$66(a5)            ; D channel modulo
  926.     move.w    #$09f0,$40(a5)            ; function = straight copy
  927.     move.w    #0,$42(a5)            ; second control word
  928.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  929.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  930.  
  931.     lea    40*256(a1),a1
  932.  
  933.     bsr    blitter_wait            ; wait for blitter
  934.  
  935.     move.l    a0,$50(a5)            ; A channel = source
  936.     move.l    a1,$54(a5)            ; D channel = destination
  937.     move.w    #0,$64(a5)            ; A channel modulo
  938.     move.w    #24,$66(a5)            ; D channel modulo
  939.     move.w    #$09f0,$40(a5)            ; function = straight copy
  940.     move.w    #0,$42(a5)            ; second control word
  941.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  942.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  943.  
  944.  
  945. game_over_wait:
  946.     move.b    vhposr(a5),d0            ; get scanline
  947.     cmp.b    #$ff,d0                ; reached line $ff?
  948.     bne.s    game_over_wait            ; not yet
  949.  
  950.     bsr    animate_pacman            ; animate pacman sprite
  951.  
  952.     move.b    $bfe001,d0            ; read hardware register
  953.     btst    #7,d0                ; fire-button = bit 7
  954.     bne.s    game_over_wait            ; not pressed - wait again!
  955.  
  956.  
  957.     lea    gfx_buffer,a0
  958.     lea    screen+(40*110)+12,a1
  959.  
  960.     bsr.s    blitter_wait            ; wait for blitter
  961.  
  962.     move.l    a0,$50(a5)            ; A channel = source
  963.     move.l    a1,$54(a5)            ; D channel = destination
  964.     move.w    #0,$64(a5)            ; A channel modulo
  965.     move.w    #24,$66(a5)            ; D channel modulo
  966.     move.w    #$09f0,$40(a5)            ; function = straight copy
  967.     move.w    #0,$42(a5)            ; second control word
  968.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  969.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  970.  
  971.     lea    16*26(a0),a0
  972.     lea    40*256(a1),a1
  973.  
  974.     bsr.s    blitter_wait            ; wait for blitter
  975.  
  976.     move.l    a0,$50(a5)            ; A channel = source
  977.     move.l    a1,$54(a5)            ; D channel = destination
  978.     move.w    #0,$64(a5)            ; A channel modulo
  979.     move.w    #24,$66(a5)            ; D channel modulo
  980.     move.w    #$09f0,$40(a5)            ; function = straight copy
  981.     move.w    #0,$42(a5)            ; second control word
  982.     move.l    #$ffffffff,$44(a5)        ; first & last word masks
  983.     move.w    #8+64*26,$58(a5)        ; size of blit & start!
  984.     rts
  985.  
  986.  
  987.  
  988. ************  wait for blitter  ************
  989.  
  990.  
  991. blitter_wait:
  992.     btst    #14,$2(a5)            ; is blitter ready?
  993.     bne.s    blitter_wait            ; not yet!
  994.     rts
  995.  
  996.  
  997.  
  998. ************  data  ************
  999.  
  1000.  
  1001. gfx_lib:    dc.b    'graphics.library',0
  1002.         even
  1003. gfx_base:    dc.l    0
  1004.  
  1005.  
  1006. x:    dc.w    0            ; x-coordinate of pacman
  1007. y:    dc.w    0            ; y-coordinate of pacman
  1008. dx:    dc.w    0            ; x-speed of pacman
  1009. dy:    dc.w    0            ; y-speed of pacman
  1010. dir:    dc.w    0            ; direction of pacman
  1011. dir2:    dc.w    0            ; direction pacman wants to go in
  1012.  
  1013. pacman_anim:    dc.w    0        ; pacman animation number
  1014.  
  1015. lives:    dc.w    0            ; player's number of lives
  1016. score:    dc.w    0            ; player's score
  1017.  
  1018.  
  1019. dir_tab:
  1020.     dc.w    -2,0,2,0,0,2,0,-2    ; pac's direction table
  1021.  
  1022.         incdir    mysource:pacman.s/
  1023. ready_gfx:    incbin    text1.raw
  1024. game_over_gfx:    incbin    text2.raw
  1025. pause_gfx:    incbin    text3.raw
  1026. gfx_buffer:    ds.b    16*26*2        ; buffer so we can save what's
  1027.                     ; under where we're drawing
  1028.  
  1029. numbers:    incbin    numbers.raw    ; numbers graphics (for score)
  1030.  
  1031. sprite1:    ds.l    18        ; control longword + 16 lines
  1032.                     ; + zero longword
  1033. sprite2:    ds.l    18
  1034.  
  1035.     include    pacman.spr_gfx.s    ; pacman graphics (source)
  1036.  
  1037. screen:    incbin    pac_screen.raw
  1038.  
  1039.  
  1040.  
  1041. ************  equates  ************
  1042.  
  1043.  
  1044. ** exec library offsets
  1045.  
  1046. forbid        equ    -132
  1047. permit        equ    -138
  1048. openlib        equ    -552
  1049. closelib    equ    -414
  1050. allocmem    equ    -198
  1051. freemem        equ    -210
  1052.  
  1053.  
  1054. ** register offsets
  1055.  
  1056. bplcon0        equ    $100
  1057. bplcon1        equ    $102
  1058. bplcon2        equ    $104
  1059. bpl1mod        equ    $108
  1060. bpl2mod        equ    $10a
  1061. bpl1pth        equ    $e0
  1062. bpl1ptl        equ    $e2
  1063. bpl2pth        equ    $e4
  1064. bpl2ptl        equ    $e6
  1065. bpl3pth        equ    $e8
  1066. bpl3ptl        equ    $ea
  1067.  
  1068. diwstrt        equ    $8e
  1069. diwstop        equ    $90
  1070. ddfstrt        equ    $92
  1071. ddfstop        equ    $94
  1072.  
  1073. dmacon        equ    $96
  1074. vhposr        equ    $6
  1075. spr0pth        equ    $120
  1076. spr0ptl        equ    $122
  1077. spr1pth        equ    $124
  1078. spr1ptl        equ    $126
  1079. spr2pth        equ    $128
  1080. spr2ptl        equ    $12a
  1081. spr3pth        equ    $12c
  1082. spr3ptl        equ    $12e
  1083. spr4pth        equ    $130
  1084. spr4ptl        equ    $132
  1085. spr5pth        equ    $134
  1086. spr5ptl        equ    $136
  1087. spr6pth        equ    $138
  1088. spr6ptl        equ    $13a
  1089. spr7pth        equ    $13c
  1090. spr7ptl        equ    $13e
  1091.  
  1092. colour0        equ    $180
  1093. colour1        equ    $182
  1094. colour2        equ    $184
  1095. colour3        equ    $186
  1096. colour4        equ    $188
  1097. colour5        equ    $18a
  1098. colour6        equ    $18c
  1099. colour7        equ    $18e
  1100. colour8        equ    $190
  1101. colour9        equ    $192
  1102. colour10    equ    $194
  1103. colour11    equ    $196
  1104. colour12    equ    $198
  1105. colour13    equ    $19a
  1106. colour14    equ    $19c
  1107. colour15    equ    $19e
  1108. colour16    equ    $1a0
  1109. colour17    equ    $1a2
  1110. colour18    equ    $1a4
  1111. colour19    equ    $1a6
  1112. colour20    equ    $1a8
  1113. colour21    equ    $1aa
  1114. colour22    equ    $1ac
  1115. colour23    equ    $1ae
  1116. colour24    equ    $1b0
  1117. colour25    equ    $1b2
  1118. colour26    equ    $1b4
  1119. colour27    equ    $1b6
  1120. colour28    equ    $1b8
  1121. colour29    equ    $1ba
  1122. colour30    equ    $1bc
  1123. colour31    equ    $1be
  1124.  
  1125.     end
  1126.